<%-- 
    Document   : giohang
    Created on : Dec 23, 2013, 5:22:04 PM
    Author     : home
--%>

<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page isErrorPage="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt" %>

<t:layout>
    <jsp:body>
        <c:set var="promotion_start" value="${(ngayHienTai >= khuyenMai.getNgayBatDau()) && (ngayHienTai <= khuyenMai.getNgayKetThuc()) && (khuyenMai.getTinhTrangKhuyenMai() == 1)}" ></c:set>
            <script language="javascript">
                function UpdateCart()
                {
                    document.updatecartForm.submit();
                }
            </script>
            <!-- if $order == 0}/cart/update else /cart/view/order/submit -->
            <form name="updatecartForm" method="POST" action="<c:url value="/GioHang/CapNhat/" />">
                <input type="hidden" name="kind" value="">
                <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
                        <td class="bgtitle">
                            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                                <tr>
                                    <td width="20"><img src="<c:url value="/resources/images/" />mui_ten.gif" /></td>
                                <td valign="bottom" class="title">Giỏ hàng</td>
                                <td width="10" valign="bottom">&nbsp;</td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td valign="top" ><img src="..<c:url value="/resources/images/" />space.gif" width="1" height="10" /></td>
                </tr>
            </table>
            <br />
            <c:if test="${count_session > 0}">
                <table width='98%' align='center' border='0' cellpadding='2' cellspacing='0' bordercolor='#CCCCCC' style='border-collapse:collapse'>
                    <tr>
                        <td class='bgmenupro border3' height='30' bgcolor='#DDDDDD' width='5%'>
                            <div align='center'>
                                <strong>STT</strong>
                            </div>
                        </td>
                        <td class='bgmenupro border3' bgcolor='#DDDDDD' width='10%'>
                            <div align='center'>
                                <strong>Hình ảnh</strong>
                            </div>
                        </td><td class='bgmenupro border3' bgcolor='#DDDDDD'>
                            <div align='center'>
                                <strong>Tên sản phẩm</strong>
                            </div>
                        </td>
                        <td class='bgmenupro border3' bgcolor='#DDDDDD' width='18%'>
                            <div align='center'>
                                <strong>Giá tiền</strong>
                            </div>
                        </td>
                        <td class='bgmenupro border3' bgcolor='#DDDDDD' width='10%'>
                            <div align='center'>
                                <strong>Số lượng</strong>
                            </div>
                        </td>
                        <!-- if $order == 0 border3 else borderfull /if -->
                        <td class='bgmenupro border3' bgcolor='#DDDDDD' width='18%'>
                            <div align='center'>
                                <strong>Thành tiền</strong>
                            </div>
                        </td>
                        <td class='bgmenupro borderfull' bgcolor='#DDDDDD' width='5%'>
                            <div align='center'>
                                <strong>Xóa</strong>
                            </div>
                        </td>
                    </tr>
                    <!-- sản phẩm mua -->
                    <c:set var="tongDonGia" value="0" />
                    <c:forEach var="sanPham" varStatus="sanPhamCounter" items="${listSanPhamGioHang}">
                        <tr>
                            <td class='fontsizecart border3'>
                                <div align='center'>${sanPhamCounter.count}</div>
                            </td>
                            <td class='border3' >
                                <div align='center'>
                                    <a href='<c:url value="/ChiTietSanPham/${sanPham.getMaSp()}" />'>
                                        <img src='<c:url value="/resources/images/" />product/${sanPham.getHinh()}' width='60' border='0'>
                                    </a>
                                </div>
                            </td>
                            <td class='fontsizecart border3'>
                                <div align='center'>
                                    <a href='<c:url value="/ChiTietSanPham/${sanPham.getMaSp()}" />' class='linkcart'>${sanPham.getTenSanPham()}</a>
                                </div>
                            </td>
                            <td class='cartprice fontsizecart border3'>
                                <c:if test="${promotion_start == true}" >
                                    <fmt:formatNumber type="number" value="${sanPham.getDonGia()*(100-khuyenMai.getPhanTram())/100}" /> VNĐ 
                                </c:if>
                                <c:if test="${promotion_start == false}" >
                                    <fmt:formatNumber type="number" value="${sanPham.getDonGia()}" /> VNĐ
                                </c:if>

                            </td>
                            <td class='border3'>
                                <div align='center'>
                                    <!-- if $order == 0 -->
                                    <input type='text' maxlength="1" size="2" name='${sanPham.getMaSp()}' value='${sanPham.getSoLuong()}' class='box_input_2' style='text-align:center;' onKeyPress="return keypress(event);" >
                                    <!-- else
                                    cart_item.quantity
                                    /if
                                    -->
                                </div>
                            </td>
                            <!-- {if $order == 0}cartprice fontsizecart border3{else}borderfull{/if} -->
                            <td class='cartprice fontsizecart border3' style="text-align: center">
                                <strong>
                                    <c:if test="${promotion_start == true}" >
                                        <c:set var="tongDonGia" value="${tongDonGia + (sanPham.getDonGia()*(100-khuyenMai.getPhanTram())/100)*sanPham.getSoLuong()}" />
                                        <fmt:formatNumber type="number" value="${(sanPham.getDonGia()*(100-khuyenMai.getPhanTram())/100)*sanPham.getSoLuong()}" /> VNĐ 
                                    </c:if>
                                    <c:if test="${promotion_start == false}" >
                                        <c:set var="tongDonGia" value="${tongDonGia + sanPham.getDonGia()*sanPham.getSoLuong()}" />
                                        <fmt:formatNumber type="number" value="${sanPham.getDonGia()*sanPham.getSoLuong()}" /> VNĐ
                                    </c:if>
                                </strong>
                            </td>
                            <td class='borderfull' >
                                <div align='center'>
                                    <a href='<c:url value="/GioHang/Xoa/${sanPham.getMaSp()}" />'>
                                        <img src='<c:url value="/resources/images/" />delete.gif' border='0'>
                                    </a>
                                </div>
                            </td>
                        </tr>
                    </c:forEach>
                    <!-- // sản phẩm mua -->
                    <tr>
                        <td colspan='5' class='cartprice fontred fontsizecart border3' >
                            <strong>Tổng giá trị</strong>
                        </td>
                        <!-- {if $order == 0}border3{else}borderfull{/if} -->
                        <td class='cartprice fontred fontsizecart border3' ><fmt:formatNumber type="number" value="${tongDonGia}" /> VNĐ</td>
                    <input type="hidden" value="${tongDonGia}" name="order_total" id="order_total">
                    <!-- if $order == 0 -->
                    <td class='borderfull' >&nbsp;</td>
                    <!-- /if -->
                    </tr>
                </table>
                <br>
                <table align='center' cellpadding='2' cellspacing='0'>
                    <tr>
                        <td>
                            <a href='<c:url value="/SanPham/" />'>
                                <img src='<c:url value="/resources/images/" />btn_continue.gif' border='0' style='cursor: pointer' ></a>
                        </td> 
                        <td>
                            <a href='<c:url value="/GioHang/Xoa/0" />'>
                                <img src='<c:url value="/resources/images/" />btn_emty.gif' border='0' style='cursor: pointer' >
                            </a>
                        </td>
                        <td>
                            <img src='<c:url value="/resources/images/" />btn_update.gif' onclick="UpdateCart()" style='cursor: pointer'>
                        </td>
                    </tr>
                </table>
            </c:if>
            <c:if test="${count_session == 0}">
                <div align="center">
                    Quý khách vui lòng chọn <a href="<c:url value="/SanPham/" />"><u>sản phẩm</u></a> để mua.
                </div>
            </c:if>
        </form>
        <br />
        <!-- {if isset($count) && $count != 0 && $order == 0 } -->
        <c:if test="${count_session > 0}" >
            <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                    <td>
                        <style type="text/css">
                            .dropcontent{
                                width: 350px;
                                height: auto;
                                padding-top:0px;
                                padding-bottom:0px;
                                padding-left:0px;
                                padding-right:0px;
                                display:block;
                            }
                        </style>
                        <script type="text/javascript">

                            /*
                             Combo-Box Viewer script- Created by and © Dynamicdrive.com
                             Visit http://www.dynamicdrive.com/ for this script and more
                             This notice MUST stay intact for legal use
                             */

                            /*if (document.getElementById){
                             document.write('<style type="text/css">\n')
                             có 1 dòng 
                             document.write('</style>\n')
                             }
                             */
                            function contractall() {
                                if (document.getElementById) {
                                    var inc = 0
                                    while (document.getElementById("dropmsg" + inc)) {
                                        document.getElementById("dropmsg" + inc).style.display = "none"
                                        inc++
                                    }
                                }
                            }

                            function expandone() {
                                if (document.getElementById) {
                                    var selectedItem = document.viewcartForm.phuongthucthanhtoan.selectedIndex
                                    contractall()
                                    document.getElementById("dropmsg" + selectedItem).style.display = "block"
                                }
                            }

                            if (window.addEventListener)
                                window.addEventListener("load", expandone, false)
                            else if (window.attachEvent)
                                window.attachEvent("onload", expandone)
                        </script>
                        <script language="javascript">
                            function gotoSubmit()
                            {
                                document.viewcartForm.kind.value = "1"
                                with (document.viewcartForm)
                                {

                                    if (order_name.value == "") {
                                        alert('Vui lòng nhập tên đầy đủ.')
                                        order_name.focus()
                                        return false
                                    }
                                    if (order_phone.value == "") {
                                        alert('Vui lòn nhập số điện thoại.')
                                        order_phone.focus()
                                        return false
                                    }
                                    if (order_address.value == "") {
                                        alert('Vui lòng nhập địa chỉ.')
                                        order_address.focus()
                                        return false
                                    }
                                    if (order_state.value == 0) {
                                        alert('Vui long chọn tỉnh thành.')
                                        order_state.focus()
                                        return false
                                    }
                                    if (phuongthucthanhtoan.value == 0) {
                                        alert('Vui lòng chọn phương thức thanh toán.')
                                        phuongthucthanhtoan.focus()
                                        return false
                                    }
                                    return true
                                }
                                //document.mainForm.submit()
                            }

                            function keypress(e) {
                                //Hàm dùng để ngăn người dùng nhập các ký tự khác ký tự số vào TextBox
                                var keypressed = null;
                                if (window.event)
                                {
                                    keypressed = window.event.keyCode; //IE
                                }
                                else
                                {
                                    keypressed = e.which; //NON-IE, Standard
                                }

                                if (keypressed < 48 || keypressed > 51) //57
                                { //CharCode của 0 là 48 (Theo bảng mã ASCII)
                                    //CharCode của 9 là 57 (Theo bảng mã ASCII)
                                    if (keypressed == 8 || keypressed == 127)
                                    {
                                        //Phím Delete và Phím Back
                                        return;
                                    }
                                    alert("Vui lòng nhập số! Từ 0 đến 3!");
                                    return false;
                                }
                            }
                            function data_change(field)
                            {
                                var check = true;
                                var value = field.value; //get characters
                                //check that all characters are digits, ., -, or ""
                                for (var i = 0; i < field.value.length; ++i)
                                {
                                    var new_key = value.charAt(i); //cycle through characters
                                    if (((new_key < "0") || (new_key > "9")) &&
                                            !(new_key == ""))
                                    {
                                        check = false;
                                        break;
                                    }
                                }
                                //apply appropriate colour based on value
                                if (!check)
                                {
                                    field.style.backgroundColor = "red"
                                    alert('Vui lòng nhập số.')
                                    order_phone.focus()
                                    return false
                                }
                                else
                                {
                                    field.style.backgroundColor = "white"
                                }
                                return true
                            }
                        </script>

                        <form name="viewcartForm" method="POST" action="<c:url value="/GioHang/HoaDon/" />" onsubmit="return gotoSubmit()">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td valign="top">&nbsp;</td>
                                </tr>
                                <tr>
                                    <td width="49%" valign="top">
                                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                                <td width="49%" height="30" background="<c:url value="/resources/images/" />bgtop.jpg" bgcolor="#DDDDDD" class="bgmenupro" style="padding-left:10px; border-top:1px #CCCCCC solid; border-left:1px #CCCCCC solid; border-right:1px #CCCCCC solid;">
                                                    <strong>Thông tin giao hàng</strong></td>
                                                <td width="2%" >&nbsp;</td>
                                                <td background="<c:url value="/resources/images/" />bgtop.jpg" bgcolor="#DDDDDD" class="bgmenupro" style="padding-left:10px; border-top:1px #CCCCCC solid; border-left:1px #CCCCCC solid; border-right:1px #CCCCCC solid;">
                                                    <strong>Phương thức thanh toán</strong></td>
                                            </tr>
                                            <tr>
                                                <td valign="top" style="border:1px #CCCCCC solid; padding:10px; height:210px;">
                                                    <table width="100%" border="0" cellpadding="3" cellspacing="0" bordercolor="#CCCCCC" style="font-family: Tahoma; font-size: 10pt; border-collapse:collapse; padding:10px">
                                                        <tr >
                                                            <td width="30%">Tên đầy đủ (*)</td>
                                                            <td width="70%">
                                                                <input name="order_name" type="text" maxlength="30" class="box_input" id="order_name" size="24"  value="${checkSession.getHoTen()}" /></td>
                                                        </tr>
                                                        <tr bgcolor="">
                                                            <td>Điện thoại (*)</td>
                                                            <td>
                                                                <input name="order_phone" type="text" maxlength="11"  class="box_input" id="order_phone" size="24"  value="${checkSession.getSoDienThoai()}" onchange="return data_change(this)" /></td>
                                                        </tr>
                                                        <tr >
                                                            <td>Địa chỉ email</td>
                                                            <td>
                                                                <input name="order_email" type="text" maxlength="30" id="order_email" value="${checkSession.getEmail()}" size="24" class="box_input" />

                                                            </td>
                                                        </tr>
                                                        <tr bgcolor="">
                                                            <td>Địa chỉ (*)</td>
                                                            <td>
                                                                <input name="order_address" type="text" maxlength="50" class="box_input" id="order_address" size="24"  value="${checkSession.getDiaChi()}" />
                                                            </td>
                                                        </tr>
                                                        <tr >
                                                            <td valign="top">Yêu cầu khác</td>
                                                            <td><textarea name="order_note" id="order_note" maxlength="100" cols="45" rows="5" class="box_input"></textarea></td>
                                                        </tr>
                                                    </table>
                                                </td>
                                                <td >&nbsp;</td>
                                                <!-- Phương thức thanh toán -->
                                                <td valign="top" style="border:1px #CCCCCC solid; padding:10px; height:210px;">
                                                    <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                                        <tr bgcolor="">
                                                            <td>
                                                                <select name="phuongthucthanhtoan" id="orderphuongthucthanhtoan" class="box_input2" onchange="expandone()">
                                                                    <option value=1 selected>Thanh toán tiền mặt khi giao hàng tận nơi</option>
                                                                    <option value=2 >Thanh toán chuyển khoản qua ngân hàng hoặc máy ATM</option>
                                                                </select>
                                                            </td>
                                                        </tr>
                                                        <tr bgcolor="">
                                                            <td>
                                                                <div id='dropmsg0' class='dropcontent'>
                                                                    <p>Nhân viên của chúng tôi sẽ giao hàng đến tận nơi bạn yêu cầu (hiện tại phương thức này chỉ áp dụng tại TP.HCM)</p>
                                                                    <p style="text-align: center;">
                                                                        <img width="200" height="123" alt="" src="<c:url value="/resources/images/" />free_shipping.png" />
                                                                    </p>
                                                                </div>
                                                                <div id='dropmsg1' class='dropcontent'>
                                                                    <p style="text-align: left;">Quý khách đến ngân hàng Vietcombank hoặc các điểm đặt máy ATM gần nhất để chuyển khoản.</p>
                                                                    (Quý khách có hoặc không có tài khoản ngân hàng đều thực hiện được việc chuyển khoản, 
                                                                    vui lòng liên hệ qua số Hotline: 0906 90 11 12 trước và sau khi chuyển tiền)
                                                                    </p>
                                                                    <p style="text-align: center;">
                                                                        <img width="120" height="120" src="<c:url value="/resources/images/" />Bank.png" alt="" />
                                                                        <br />
                                                                        <strong>
                                                                            Ngân hàng ngoại thương HCM (Vietcombank)<br>
                                                                            Tên TK: Trần Quốc Minh - Số TK: 0511003860293
                                                                        </strong>
                                                                    </p>
                                                                </div>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>

                                        </table>
                                    </td>
                                </tr>
                            </table>
                            <br>
                            <table border="0" align="center" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td>
                                        <input type="image" src="<c:url value="/resources/images/" />btn_booknow.gif"  />

                                    </td>
                                </tr>
                            </table>
                        </form>

                    </td>
                </tr>
            </table>
            <script type="text/javascript">
                var persistmenu = "yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
                var persisttype = "sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only

                /*if (document.getElementById){ //DynamicDrive.com change
                 document.write('<style type="tdocumentext/css">\n')
             
                 document.write('</style>\n')
                 }
                 */
                function SwitchMenu(obj) {
                    if (document.getElementById) {
                        var el = document.getElementById(obj);
                        var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
                        if (el.style.display != "block") { //DynamicDrive.com change
                            for (var i = 0; i < ar.length; i++) {
                                if (ar[i].className == "submenu") //DynamicDrive.com change
                                    ar[i].style.display = "none";
                            }
                            el.style.display = "block";
                        } else {
                            el.style.display = "none";
                        }
                    }
                }

                function get_cookie(Name) {
                    var search = Name + "="
                    var returnvalue = "";
                    if (document.cookie.length > 0) {
                        offset = document.cookie.indexOf(search)
                        if (offset != -1) {
                            offset += search.length
                            end = document.cookie.indexOf(";", offset);
                            if (end == -1)
                                end = document.cookie.length;
                            returnvalue = unescape(document.cookie.substring(offset, end))
                        }
                    }
                    return returnvalue;
                }

                function onloadfunction() {
                    if (persistmenu == "yes") {
                        var cookiename = (persisttype == "sitewide") ? "switchmenu" : window.location.pathname
                        var cookievalue = get_cookie(cookiename)
                        if (cookievalue != "")
                            document.getElementById(cookievalue).style.display = "block"
                    }
                }

                function savemenustate() {
                    var inc = 1, blockid = ""
                    while (document.getElementById("sub" + inc)) {
                        if (document.getElementById("sub" + inc).style.display == "block") {
                            blockid = "sub" + inc
                            break
                        }
                        inc++
                    }
                    var cookiename = (persisttype == "sitewide") ? "switchmenu" : window.location.pathname
                    var cookievalue = (persisttype == "sitewide") ? blockid + ";path=/" : blockid
                    document.cookie = cookiename + "=" + cookievalue
                }

                if (window.addEventListener)
                    window.addEventListener("load", onloadfunction, false)
                else if (window.attachEvent)
                    window.attachEvent("onload", onloadfunction)
                else if (document.getElementById)
                    window.onload = onloadfunction

                if (persistmenu == "yes" && document.getElementById)
                    window.onunload = savemenustate

            </script>
            <!-- end: swith menu !-->
            <script language="JavaScript1.1">
    <!--
                var whichlink = 0
                var whichimage = 0
                var blenddelay = (ie) ? document.images.slide.filters[0].duration * 1000 : 0
                function slideit() {
                    if (!document.images)
                        return
                    if (ie)
                        document.images.slide.filters[0].apply()
                    document.images.slide.src = imageholder[whichimage].src
                    if (ie)
                            document.images.slide.filters[0].play()                 whichlink = whichimage
                        whichimage = (whichimage < slideimages.length - 1) ? whichimage + 1 : 0
                    setTimeout("slideit()", slidespeed + blenddelay)
                }
                slideit()
    //-->
            </script> 
        </c:if>
    </jsp:body>
</t:layout>